package com.pat.java.base.event;

import java.applet.Applet;
import java.awt.Button;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class UseMouseEvent extends Applet implements MouseListener,
		MouseMotionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Button btn;

	public void init() {
		btn = new Button("演示鼠标事件");
		add(btn);

		btn.addMouseListener(this);
		btn.addMouseMotionListener(this);

		this.addMouseListener(this);
		this.addMouseMotionListener(this);
	}

	public void mouseClicked(MouseEvent e) {
		Point p = new Point();
		if (e.getSource() == btn) {
			if (e.getClickCount() == 1) {
				btn.setLabel("单击鼠标事件");
			} else if (e.getClickCount() == 2) {
				btn.setLabel("双击鼠标事件");
			}

		} else {
			if (e.getClickCount() == 1) {
				p = e.getPoint();
				showStatus(p.x + "， " + p.y + "单击鼠标");
			} else if (e.getClickCount() == 2) {
				p = e.getPoint();
				showStatus(p.x + "， " + p.y + "双击鼠标");

			}
		}
	}

	public void mouseEntered(MouseEvent e) {
		if (e.getSource() == btn)
			btn.setLabel("进入Button");
		else
			showStatus("进入Applet");
	}

	public void mouseExited(MouseEvent e) {
		if (e.getSource() == btn)
			btn.setLabel("移出Button");

		else
			showStatus("移出Applet");
	}

	public void mousePressed(MouseEvent e) {
		if (e.getSource() == btn)
			btn.setLabel("按下鼠标");
		else
			showStatus("按下鼠标");
	}

	public void mouseReleased(MouseEvent e) {

		if (e.getSource() == btn)
			btn.setLabel("松开鼠标");
		else
			showStatus("松开鼠标");
	}

	public void mouseMoved(MouseEvent e) {
		if (e.getSource() == btn)
			btn.setLabel("移动鼠标");
		else
			showStatus("移动鼠标，移动到" + e.getX() + "， " + e.getY());
	}

	public void mouseDragged(MouseEvent e) {
		if (e.getSource() == btn)
			btn.setLabel("拖动鼠标");
		else
			showStatus("拖动鼠标");
	}
}